import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { loginPasswordApi } from '@/types/user'

export const useUser = defineStore(
  'user',
  () => {
    const userInfo = ref<loginPasswordApi>()
    const setUserInfo = (val: loginPasswordApi) => {
      userInfo.value = val
    }
    // 清除用户信息与token
    const logout = () => {
      userInfo.value = undefined
    }
    return { userInfo, setUserInfo, logout }
  },
  {
    persist: {
      paths: ['userInfo']
    }
  }
)
